#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve()
{
    ll x, n;
    cin >> x >> n;
    ll t = 1;
    ll sum = 0;
    for (ll i=1; i <= n;i++)
    {
        sum += t * x;
        t *= -1;
    }
    cout << sum << endl;
}
int main()
{
    ll t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
}